//
//  NewsViewController.m
//  LOLProject
//
//  Created by qianfeng001 on 16/3/23.
//  Copyright © 2016年 盛宣伟. All rights reserved.
//

#import "NewsViewController.h"
#import "DBSphereView.h"
#import "OtherViewController.h"
#import "FisrtViewController.h"
#import "ChanViewController.h"
#import "HeroViewController.h"
#import "InformationViewController.h"
#import "MasterViewController.h"
#import "HalfPriceViewController.h"
#import "DetailViewController.h"
#import "GamePlayViewController.h"
#define random arc4random() % 256 / 255.0
@interface NewsViewController ()

@property (nonatomic, retain) DBSphereView *sphereView;

@end

@implementation NewsViewController

- (void)viewDidLoad {
    self.title = @"频道";
    [self createSphereView];
}

- (void)createSphereView{

    self.view.backgroundColor = [UIColor whiteColor];
    self.sphereView = [[DBSphereView alloc] initWithFrame:CGRectMake(0, APPScreenHeight / 5, APPScreenWidth, APPScreenHeight / 2 + 100)];
    NSArray *arr = @[@"首页",@"分类",@"英雄",@"资讯",@"高手",@"比赛",@"专栏",@"战队",@"攻略",@"美图",@"周免英雄",@"天赋推荐",@"半价英雄",@"Miss解说",@"小智解说",@"小苍解说",@"faker",@"文森特",@"陆雪琪",@"若风",@"首页",@"分类",@"英雄",@"资讯",@"高手",@"比赛",@"专栏",@"战队",@"攻略",@"美图",@"周免英雄",@"天赋推荐",@"半价英雄",@"Miss解说",@"小智解说",@"小苍解说",@"faker",@"文森特",@"陆雪琪",@"若风"];
    
    
    NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:0];
    for (NSInteger i = 0; i < arr.count; i ++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        [btn setTitle:[NSString stringWithFormat:@"%@",arr[i]] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor colorWithRed:random green:random blue:random alpha:1] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:24.];
        btn.frame = CGRectMake(0, 0, 120, 40);
        [btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [array addObject:btn];
        [self.sphereView addSubview:btn];
    }
    [self.sphereView setCloudTags:array];
    self.sphereView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.sphereView];
}

- (void)buttonPressed:(UIButton *)btn
{
    [self.sphereView timerStop];
    
    [UIView animateWithDuration:0.3 animations:^{
        btn.transform = CGAffineTransformMakeScale(2., 2.);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.3 animations:^{
            btn.transform = CGAffineTransformMakeScale(1., 1.);
        } completion:^(BOOL finished) {
            
            //添加函数
            [self cleckBtn:btn];
            
            [self.sphereView timerStart];
        }];
    }];
}

- (void) cleckBtn:(UIButton *) btn {
    
    NSString * btnNum = [self findURLFromSource:btn.titleLabel.text];

    switch ([btnNum integerValue]) {
        case 0:
        {
        FisrtViewController *fv = [[FisrtViewController alloc] init];
        [self.navigationController pushViewController:fv animated:YES];
        break;
        }
        case 1:
        {
            ChanViewController *cv = [[ChanViewController alloc] init];
            cv.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:cv animated:YES];
            break;
        }
        case 2:
        {
            HeroViewController *hv = [[HeroViewController alloc] init];
            [self.navigationController pushViewController:hv animated:YES];
            break;
        }
        case 3:
        {
            InformationViewController *iv = [[InformationViewController alloc] init];
            [self.navigationController pushViewController:iv animated:YES];
            break;
        }
        case 4:
        {

            MasterViewController *mc = [[MasterViewController alloc] init];
            mc.hidesBottomBarWhenPushed = YES;
            mc.accessibilityFrame = self.view.frame;
            [self.navigationController pushViewController:mc animated:YES];
            break;
        }
            case 5:
        case 12:
        {
            HalfPriceViewController *mc = [[HalfPriceViewController alloc] init];
            mc.navigationController.navigationBarHidden = YES;
            mc.hidesBottomBarWhenPushed = YES;
        
            [self.navigationController pushViewController:mc animated:YES];
            break;
        }
        case 13:
        {
            DetailViewController *de = [DetailViewController new];
            de.iddd = @"202";
            [self.navigationController pushViewController:de animated:YES];
             break;
        }
        case 14:
        {
            DetailViewController *de = [DetailViewController new];
            de.iddd = @"144";
            [self.navigationController pushViewController:de animated:YES];
             break;
        }
        case 15:
        {
            DetailViewController *de = [DetailViewController new];
            de.iddd = @"153";
            [self.navigationController pushViewController:de animated:YES];
             break;
        }
        case 16:
        {
            DetailViewController *de = [DetailViewController new];
            de.iddd = @"226";
            [self.navigationController pushViewController:de animated:YES];
            break;
        }
        case 17:
        {
            DetailViewController *de = [DetailViewController new];
            de.iddd = @"266";
            [self.navigationController pushViewController:de animated:YES];
            break;
        }
        case 18:
        {
            DetailViewController *de = [DetailViewController new];
            de.iddd = @"481";
            [self.navigationController pushViewController:de animated:YES];
            break;
        }
        case 19:
        {
            DetailViewController *de = [DetailViewController new];
            de.iddd = @"160";
            [self.navigationController pushViewController:de animated:YES];
            break;
        }
        default:
            break;
    }
//    OtherViewController * ttVc = [[OtherViewController alloc]init];
//    NSString * url = [NSString stringWithFormat:@"%@",btnNum];
//    ttVc.listUrl = url ;
//    ttVc.type = btnNum ;
//    ttVc.title = btn.titleLabel.text ;
//    [self.navigationController pushViewController:ttVc animated:YES];
}

//拼接网址
- (NSString *) findURLFromSource: (NSString *)buttonName {

    NSDictionary * urlSource = @{@"首页":@"0",@"分类":@"1",@"英雄":@"2",@"资讯":@"3",@"高手":@"4",@"比赛":@"5",@"专栏":@"6",@"战队":@"7",@"攻略":@"8",@"美图":@"9",@"周免英雄":@"10",@"天赋推荐":@"11",@"半价英雄":@"12",@"Miss解说":@"13",@"小智解说":@"14",@"小苍解说":@"15",@"faker":@"16",@"文森特":@"17",@"陆雪琪":@"18",@"若风":@"19"};
    NSString *  num = urlSource[buttonName];
    return num ;
}

- (void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}



@end
